<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Home extends Admin_Controller {

	//后台首页
	public function index()
	{


		$data = array(
			'title' => 'My Title',
			'heading' => 'My Heading',
			'message' => 'My Message'
		);

		$this->display('home/index.html', $data);
	}


	//管理员修改自己的密码
	public function editpass()
	{
		$this->display('home/editpass.html');
	}


	//保存自己修改的密码
	public function savepass()
	{
		$password = trim($this->input->post('password', true));
		$re_password = trim($this->input->post('re_password', true));

		if(empty($password))
		{
			$this->error('请输入密码！');
		}
		elseif($password != $re_password)
		{
			$this->error('两次输入的密码不相同！');
		}
		elseif(strlen($password) < 6)
		{
			$this->error('密码不能小于6位！');
		}

		//加载后台用户model
		$this->load->model('admin/admin_model', 'edit_self');

		$salt = PassGen(6); //生成6位密码混淆字符串

		$this->edit_self->id = $this->admin->id; //管理员id
		$this->edit_self->salt = $salt;
		$this->edit_self->password = md5($salt . md5($password));

		$this->edit_self->update();

		$this->success('我的密码 -> 更新成功！'); //编辑时不更新tab
	}


	//管理员修改自己的资料页面
	public function editinfo()
	{
		$this->display('home/editinfo.html');
	}


	//保存自己修改的资料
	public function saveinfo()
	{
		//加载后台用户model
		$this->load->model('admin/admin_model', 'edit_self');

		$this->edit_self->id = $this->admin->id; //管理员id
		$this->edit_self->nickname = trim($this->input->post('nickname', true));
		$this->edit_self->mobile = trim($this->input->post('mobile', true));
		$this->edit_self->email = trim($this->input->post('email', true));

		$this->edit_self->update();

		$this->success('我的资料 -> 更新成功！'); //编辑时不更新tab
	}


}